<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Productview_model extends CI_Model
{

    public function getCategory($parent, $langCode)
    {
        $this->db->select("id, name_$langCode as 'name'");
        $this->db->from('product');
        $this->db->where('parent_id', $parent);
        $r = $this->db->get();
        $return = $r->result_array();
        $r->free_result();
        return $return;
    }
    
    function get_product_by_id($id, $lang) {
        $data = array();
        $this->db->select("product_id, image_src, name_$lang as 'name', summary_$lang as 'summary', content_$lang as 'content'");
        $this->db->from('item');
        $this->db->where('id', $id);
        $data = $this->db->get()->result_array();
        return $data;
    }
    
    function getProductIdById($id) {
                $this->db->select("product_id");
		$this->db->from("item");
		$this->db->where('id', $id);
		return $this->db->get()->result_array();
    }


    public function getCategoryById($id, $lang) 
	{
		$this->db->select("id, name_$lang as 'name', parent_id");
		$this->db->from("product");
		$this->db->where('id', $id);
		return $this->db->get()->result_array();
	}

    public function getProductByCatId($id, $langCode)
    {
        $this->db->select("item.id, name_$langCode as 'name', image_src, content_$langCode as 'content', summary_$langCode as 'summary'");
        $this->db->from('item');
        $this->db->where('product_id',$id);
        $this->db->limit(4);
        $r = $this->db->get();
        $return = $r->result_array();
        $r->free_result();
        return $return;
    }
}

?>
